package com.hdax.dmw.pay.api;

import com.hdax.dmw.dtos.order.OrderDetailDto;
import com.hdax.dmw.pay.service.ConfirmPayService;
import com.hdax.dmw.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.Map;

@RestController
@RequestMapping(path = "/pay/p/")
public class ConfirmPayApi {

    @Autowired
    private ConfirmPayService confirmPayService;

    @PostMapping(path = "/confirmpay")
    public Result<OrderDetailDto> confrimPay(@RequestBody Map<String,String> params){
        String orderNo = params.get("orderNo");
        return confirmPayService.orderDetail(orderNo);
    }

    @PostMapping(path = "/alipay")
    public void alipay(@RequestBody Map<String,String> params,
                       HttpServletResponse response) throws Exception{
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String orderNo = params.get("orderNo");
        String result = confirmPayService.alipay(orderNo);
        out.write(result);
    }

}
